<template>
  <div class="reviewOuter">
    <!-- 面包屑导航 -->
    <div class="reviewTop">
      <el-breadcrumb :separator-icon="ArrowRight">
        <el-breadcrumb-item :to="{ path: '/layout/portal' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>评论管理</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <!-- 标题 -->
    <h3 class="title">评论管理</h3>
    <!-- 内容区 -->
    <div class="review">
      <!-- 评论列表 -->
      <div class="review_list">
        <el-table height="400" :data="tableData" stripe style="width: 100%">
          <el-table-column align="center" type="index" index="index" width="40" />
          <el-table-column align="center" prop="title" label="文章标题" width="120" />
          <el-table-column align="center" prop="username" label="用户" width="160" />
          <el-table-column align="center" prop="discuss" label="评论" width="200" />
          <el-table-column align="center" prop="auditStatus" label="审核状态" width="160" />
          <el-table-column align="center" label="操作">
            <template #default="scope">
              <el-button type="danger" size="small" @click="delDiscuss(scope.row._id)" :icon="Delete" circle />
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
  </div>

</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import { ArrowRight } from '@element-plus/icons-vue'
import {
  Delete,
} from '@element-plus/icons-vue'

import { ElMessage } from 'element-plus';
import { getDiscussAllApi, delDiscussApi } from '../../service/apiModule/discussApi'

onMounted(() => {
  getDiscussAll()
})

// 评论列表序号
const indexMethod = (index: number) => {
  return index
}

// 评论列表数据
const tableData = ref([
  {
    auditStatus: true,
    discuss: "123",
    title: "CSS小技术",
    username: "admin",
    _id: "646f2e3c13e76f8a3bbf8521",
  },
])

// 获取评论
const getDiscussAll = async () => {
  const { data: res } = await getDiscussAllApi()
  if (res.status.code !== 200) {
    ElMessage.error('评论获取失败!')
  } else {
    ElMessage.success('评论获取成功!')
    tableData.value = res.data
  }
}

// 删除评论
const delDiscuss = async (id: String) => {
  const { data: res } = await delDiscussApi({ id })
  if (res.status.code !== 200) {
    ElMessage.error('删除失败!')
  } else {
    ElMessage.success('删除成功!')
    getDiscussAll()
  }
}

</script>

<style lang="scss" scoped>
$H: 91vh;

.reviewOuter {
  width: 100%;
  height: $H;
  background-color: rgb(243, 243, 243);
  padding: 20px;

  .reviewTop {
    width: 100%;
    background-color: rgba(255, 255, 255, .6);
    padding: 10px 10px;
    border-radius: 10px;
  }

  .title {
    margin-top: 20px;
    margin-bottom: 20px;
  }

  .review {
    background-color: #fff;
    padding: 10px 0 0 10px;
    border-radius: 10px;
    min-height: 60%;
    max-height: 76%;

    .review_top {
      width: 100%;
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 10px 30px 10px 10px;

      .review_search {
        width: 30%;
        display: flex;
        align-items: center;

        &>.el-input {
          margin-right: 6px;
        }

        .m-2 {
          margin-left: 20px;
          width: 300px;
        }
      }
    }

  }

  .demo-pagination-block {
    height: 52px;
    background-color: #fff;
    margin-top: 10px;
    padding: 10px;
    border-radius: 10px;
    position: relative;

    .el-pagination {
      position: absolute;
      right: 10px;
    }
  }
}
</style>